#include "totalitem.h"

#include <QStyleOption>
#include <QRegularExpressionValidator>
#include <QRegularExpression>

#include <QPainter>

#include "../../uitools/vhc/constview4fun.h"
#include "../../uitools/vhc/constview4id.h"

namespace kepen {
namespace core {

TotalItem::TotalItem(QWidget *parent) : QWidget(parent), m_nTotal(0)
{
    QString nameThiz("total_item");
    QString cssThiz = QString("QWidget#%1{background-color:transparent;font-size:%2px;}").arg(nameThiz).arg(TextSize_ToolBar);
    QString cssLabel = QString("QLabel{font-family:Microsoft Yahei;font-size:%1px;}").arg(TextSize_ToolBar);
    m_pLabel = new QLabel("共 0 条", this);
    setObjectName(nameThiz);
    setStyleSheet(cssThiz);

    m_pLabel->setStyleSheet(cssLabel);
    // m_pLabel->adjustSize();
    // setMinimumSize(m_pLabel->size().width(), m_pLabel->size().height());
    // m_pLabel->move(0, (height() - m_pLabel->height()) / 2);
}

TotalItem::~TotalItem()
{

}

void TotalItem::SetTotal(int nTotal,int nTotalPage)
{
    if(nTotal < 0) return;
    m_nTotal = nTotal;
    QString str = QString::asprintf("共%d条%d页",nTotal,nTotalPage);
    m_pLabel->setText(str);
     m_pLabel->adjustSize();
    setMinimumSize(m_pLabel->size().width(), m_pLabel->size().height());
     m_pLabel->move(0, (height() - m_pLabel->height()) / 2);
}

int TotalItem::GetTotal() const
{
    return m_nTotal;
}

void TotalItem::paintEvent(QPaintEvent *event)
{
    QStyleOption opt;
    opt.initFrom(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
    QWidget::paintEvent(event);
}


}
}
